#include "stdafx.h"
#include "injecter.h"
#include <iostream>


injecter::injecter(myBaseIEObj *pIEObj, HWND hWnd):
	m_pIEObj(pIEObj), m_hWnd(hWnd)
{
	FILE *fp = fopen("jscode.js", "rb");
	memset(m_jscode, 0, sizeof(m_jscode));
	fread(m_jscode, sizeof(char), sizeof(m_jscode), fp);
}

injecter::~injecter()
{
	
}

BOOL injecter::InjectJsCode()
{
	m_pIEObj->InjectJsCode(m_jscode);
	return TRUE;
}

BOOL injecter::AddName(const std::wstring &wstrName)
{
	m_Names.push_back(wstrName);
	return TRUE;
}

BOOL injecter::OnGetNameOver()
{
	PostMessage(m_hWnd, WM_BEGIN_NAV, 0, 0);
	return TRUE;
}

BOOL injecter::Nav()
{
	static unsigned int cur = 0;
	if (cur < m_Names.size()){
		m_pIEObj->navigateUrl(m_Names[cur++].c_str());
	} else {
		cur = 0;
		m_Names.clear();
		PostMessage(m_hWnd, WM_END_NAV, 0, 0);
	}
	return TRUE;
}